<?PHP
$range = 20;
$zencol = 5;
$vtbcol = 6;
$vtb = array();
$zen = array();
$file = fopen('vtb.csv', 'r');
while (($line = fgetcsv($file, 0, ';')) !== FALSE) {
  //$line is an array of the csv elements
  $vtb[] = $line;
}
fclose($file);
$file = fopen('zen.csv', 'r');
while (($line = fgetcsv($file)) !== FALSE) {
  //$line is an array of the csv elements
  $zen[] = $line;
}
fclose($file);

echo "Unmatched Bank transacions:\n";
$count = 0;
foreach($vtb as  $vtbRow) {
    $try = $range; 
//    foreach($vtbRow as $val) {
//        if(is_numeric($val)) {
//    	$vtbsum = $val;
//        }
//    }
    $vtbsum = $vtbRow[$vtbcol];
    while($try > 0) {
	$found = false;
        unset($zensum);
	foreach($zen as $key => $zenRow){
//	    foreach($zenRow as $key => $val) {
//		if(is_numeric($val)) {
//		    $zensum = $val;
//		}
//	    }
            $zensum = $zenRow[$zencol];
            $a = (float)str_replace(',', '.', $vtbsum);
            $b = (float)str_replace(',', '.', $zensum);
	    if(@$zensum AND (abs($a) == abs($b))) {
		unset($zen[$key]);
		$found = true;
		break 2;
	    }
	}
	$try--;
    }
    if(!$found) {
        $count++;
        echo implode(' ', $vtbRow).PHP_EOL;
    }
}
echo "total: $count\n\n";
echo "Unmatching Zen transactions:\n";
if(count($zen)==0) {
    echo "none";
} else {
    foreach($zen as $zenRow) {
	echo implode(' ', $zenRow).PHP_EOL;
    }
} 